package com.satoken.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserSessionController {

    @RequestMapping("/sessionGetId")
    public String sessionGetId(){
        return StpUtil.getSession().getId()
                + "," +
                StpUtil.getSession().getCreateTime()
                + "," +
                StpUtil.getSession().getDataMap();
    }

    @RequestMapping("/keys")
    public SaResult keys(){
        StpUtil.getSession().set("username","123").update();
        return SaResult.data(StpUtil.getSession().keys());
    }

    @RequestMapping("/getAnonTokenSession")
    public SaResult getAnonTokenSession(){

        return SaResult.data(StpUtil.getAnonTokenSession());
    }
}
